package com.lizba.redis.pipeline;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

import java.io.IOException;

/**
 * <p>
 *  测试pipeline
 * </p>
 *
 * @Author: Liziba
 * @Date: 2021/9/14 22:43
 */
public class PipelineTest {

    public static void main(String[] args) throws IOException {
        Jedis client = new Jedis("127.0.0.1", 6379);

        long startPipe = System.currentTimeMillis();
        Pipeline pipe = client.pipelined();
        pipe.multi();
        for (int i = 0; i < 100000; i++) {
            pipe.set("pipe" + i, i + "" );
        }
        pipe.exec();
        pipe.close();
        long endPipe = System.currentTimeMillis();
        System.out.println("pipeline set cost time : " + (endPipe - startPipe) + "ms");


        for (int i = 0; i < 100000; i++) {
            client.set("normal" + i, i + "");
        }
        System.out.println("normal set cost time : " + (System.currentTimeMillis() - endPipe)+ "ms");
    }

}
